package com.wh.testDanLi;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 静态内部类
 */
public class DanLiDemo3 {
    private DanLiDemo3(){

    }
    public static DanLiDemo3 getInstance(){
        return InnerClass.danLiDemo3;
    }
    public static class InnerClass{
        private static final DanLiDemo3 danLiDemo3=new DanLiDemo3();
    }

    //反射
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        DanLiDemo3 instance = DanLiDemo3.getInstance();
        Constructor<DanLiDemo3> declaredConstructor = DanLiDemo3.class.getDeclaredConstructor(null);
        //设置Accessible的访问标志位为Ture，就可以通过反射获取私有变量的值，在访问时会忽略访问修饰符的检查
        declaredConstructor.setAccessible(true);
        DanLiDemo3 danLiDemo3 = declaredConstructor.newInstance();
        System.out.println(danLiDemo3==instance);
    }
}
